/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restauranteaplicacion.Modificaciones;

import restauranteaplicacion.Ingresos.*;
import Clases.Observador;
import CapaNegocios.CNProveedor;
import java.util.List;
import entidad.Proveedores;
import java.awt.Component;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JOptionPane;
import restauranteaplicacion.MDI;
import entidad.Usuarios;
import entidad.Tipousuarios;
import entidad.Puestos;
import CapaNegocios.CNUsuarios;
import CapaNegocios.CNTipoUsuarios;
import CapaNegocios.CNPuestos;

/**
 *
 * @author Victor
 */
public class ModificacionUsuarios extends javax.swing.JInternalFrame implements Observer{

    /**
     * Creates new form IngresoEmpleado
     */
    Observador obs;
    //DefaultTableModel modelo;
    @SuppressWarnings("empty-statement")
    public ModificacionUsuarios() {
        initComponents();
        obs=new Observador();
        obs.addObserver(this);
    }
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        usuariosList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(controlrestaurante.pmf.getInstancia().getEMF().createEntityManager().createNamedQuery("Usuarios.findAll").getResultList());
        puestos1 = new entidad.Puestos();
        usuarios1 = new entidad.Usuarios();
        tipousuarios1 = new entidad.Tipousuarios();
        tipousuarioslist = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(controlrestaurante.pmf.getInstancia().getEMF().createEntityManager().createNamedQuery("Tipousuarios.findAll").getResultList());
        puestoslist = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(controlrestaurante.pmf.getInstancia().getEMF().createEntityManager().createNamedQuery("Puestos.findAll").getResultList());
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        Tabla = new javax.swing.JTable();
        txtNombre = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        btnAgregar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        btnEliminar3 = new javax.swing.JButton();
        btnAgregar3 = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jLayeredPane4 = new javax.swing.JLayeredPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        TablaTipo = new javax.swing.JTable();
        jLabel22 = new javax.swing.JLabel();
        btnAgregar1 = new javax.swing.JButton();
        btnModificar1 = new javax.swing.JButton();
        btnEliminar1 = new javax.swing.JButton();
        jLayeredPane5 = new javax.swing.JLayeredPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        TablaPuesto = new javax.swing.JTable();
        jLabel23 = new javax.swing.JLabel();
        btnAgregar2 = new javax.swing.JButton();
        btnModificar2 = new javax.swing.JButton();
        btnEliminar2 = new javax.swing.JButton();

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaPuesto, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.descripcion}"), puestos1, org.jdesktop.beansbinding.BeanProperty.create("descripcion"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaPuesto, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.empleadosCollection}"), puestos1, org.jdesktop.beansbinding.BeanProperty.create("empleadosCollection"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaPuesto, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idPuestos}"), puestos1, org.jdesktop.beansbinding.BeanProperty.create("idPuestos"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaPuesto, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nombrePuesto}"), puestos1, org.jdesktop.beansbinding.BeanProperty.create("nombrePuesto"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.activo}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("activo"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.empleadoidEmpleado}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("empleadoidEmpleado"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idUsuarios}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("idUsuarios"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.ordenCollection}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("ordenCollection"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.password}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("password"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.tipoUsuarioidTipoUsuario}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("tipoUsuarioidTipoUsuario"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, Tabla, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.userName}"), usuarios1, org.jdesktop.beansbinding.BeanProperty.create("userName"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaTipo, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.descripcion}"), tipousuarios1, org.jdesktop.beansbinding.BeanProperty.create("descripcion"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaTipo, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idTipoUsuarios}"), tipousuarios1, org.jdesktop.beansbinding.BeanProperty.create("idTipoUsuarios"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaTipo, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nombre}"), tipousuarios1, org.jdesktop.beansbinding.BeanProperty.create("nombre"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, TablaTipo, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.usuariosCollection}"), tipousuarios1, org.jdesktop.beansbinding.BeanProperty.create("usuariosCollection"));
        bindingGroup.addBinding(binding);

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setIconifiable(true);
        setTitle("Creacion Meseros");
        setAutoscrolls(true);
        setMaximumSize(new java.awt.Dimension(985, 649));
        setMinimumSize(new java.awt.Dimension(985, 649));
        setPreferredSize(new java.awt.Dimension(985, 649));
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));

        jPanel1.setBackground(new java.awt.Color(54, 149, 240));
        jPanel1.setMaximumSize(new java.awt.Dimension(2000, 50));
        jPanel1.setMinimumSize(new java.awt.Dimension(246, 50));
        jPanel1.setPreferredSize(new java.awt.Dimension(1000, 50));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Control Usuarios");
        jPanel1.add(jLabel4);

        getContentPane().add(jPanel1);

        jPanel4.setPreferredSize(new java.awt.Dimension(988, 430));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(494, 500));

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/circle-x-3x.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setPreferredSize(new java.awt.Dimension(89, 53));
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, usuariosList, Tabla);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${userName}"));
        columnBinding.setColumnName("UserName");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${empleadoidEmpleado.nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${empleadoidEmpleado.apellido}"));
        columnBinding.setColumnName("Apellido");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tipoUsuarioidTipoUsuario.nombre}"));
        columnBinding.setColumnName("Tipo Usuario");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${password}"));
        columnBinding.setColumnName("Contraseña");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${empleadoidEmpleado.puestoidPuesto.nombrePuesto}"));
        columnBinding.setColumnName("Puesto");
        columnBinding.setColumnClass(String.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        Tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(Tabla);

        jScrollPane2.setBounds(10, 60, 840, 140);
        jLayeredPane3.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        txtNombre.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });
        txtNombre.setBounds(120, 20, 390, 30);
        jLayeredPane3.add(txtNombre, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel20.setText("<html>Buscar por nombre de Usuario </html>");
        jLabel20.setBounds(10, 10, 100, 40);
        jLayeredPane3.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/plus-3x.png"))); // NOI18N
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        btnAgregar.setBounds(630, 10, 50, 40);
        jLayeredPane3.add(btnAgregar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/pencil-3x.png"))); // NOI18N
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        btnModificar.setBounds(690, 10, 50, 40);
        jLayeredPane3.add(btnModificar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/x-3x.png"))); // NOI18N
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        btnEliminar.setBounds(750, 10, 50, 40);
        jLayeredPane3.add(btnEliminar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar3.setText("Mesas");
        btnEliminar3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminar3ActionPerformed(evt);
            }
        });
        btnEliminar3.setBounds(820, 20, 73, 30);
        jLayeredPane3.add(btnEliminar3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/reload-3x.png"))); // NOI18N
        btnAgregar3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregar3ActionPerformed(evt);
            }
        });
        btnAgregar3.setBounds(520, 10, 50, 40);
        jLayeredPane3.add(btnAgregar3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel21.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel21.setText("Usuarios");

        jLayeredPane4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipousuarioslist, TablaTipo);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding.setColumnName("Nombre de Tipo Usuario");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        TablaTipo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaTipoMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(TablaTipo);

        jScrollPane3.setBounds(30, 80, 350, 140);
        jLayeredPane4.add(jScrollPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel22.setText("<html>Control de Tipo de Usuarios </html>");
        jLabel22.setBounds(10, 10, 100, 40);
        jLayeredPane4.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/plus-3x.png"))); // NOI18N
        btnAgregar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregar1ActionPerformed(evt);
            }
        });
        btnAgregar1.setBounds(120, 20, 50, 40);
        jLayeredPane4.add(btnAgregar1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnModificar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/pencil-3x.png"))); // NOI18N
        btnModificar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificar1ActionPerformed(evt);
            }
        });
        btnModificar1.setBounds(190, 20, 50, 40);
        jLayeredPane4.add(btnModificar1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/x-3x.png"))); // NOI18N
        btnEliminar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminar1ActionPerformed(evt);
            }
        });
        btnEliminar1.setBounds(260, 20, 57, 40);
        jLayeredPane4.add(btnEliminar1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLayeredPane5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, puestoslist, TablaPuesto);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombrePuesto}"));
        columnBinding.setColumnName("Nombre Puesto");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcion}"));
        columnBinding.setColumnName("Descripcion");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        TablaPuesto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaPuestoMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(TablaPuesto);

        jScrollPane4.setBounds(40, 80, 350, 140);
        jLayeredPane5.add(jScrollPane4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel23.setText("<html>Control de Tipo de Puestos </html>");
        jLabel23.setBounds(10, 10, 100, 40);
        jLayeredPane5.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnAgregar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/plus-3x.png"))); // NOI18N
        btnAgregar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregar2ActionPerformed(evt);
            }
        });
        btnAgregar2.setBounds(130, 20, 50, 40);
        jLayeredPane5.add(btnAgregar2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnModificar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/pencil-3x.png"))); // NOI18N
        btnModificar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificar2ActionPerformed(evt);
            }
        });
        btnModificar2.setBounds(200, 20, 50, 40);
        jLayeredPane5.add(btnModificar2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        btnEliminar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/restauranteaplicacion/Ingresos/x-3x.png"))); // NOI18N
        btnEliminar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminar2ActionPerformed(evt);
            }
        });
        btnEliminar2.setBounds(280, 20, 50, 40);
        jLayeredPane5.add(btnEliminar2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel21)
                            .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 902, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLayeredPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(61, 61, 61)
                                .addComponent(jLayeredPane5))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLayeredPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLayeredPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(322, 322, 322))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 968, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 569, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel4);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

  
    
    private void CargarTablaUsuarios(List<Usuarios> listatemp){
        usuariosList.clear();
        agregarLista(usuariosList,listatemp);
    }
    
    private void CargarTablaPuestos(List<Puestos> listatemp){
        puestoslist.clear();
        agregarLista(puestoslist,listatemp);
    }
    
    private void CargarTablaTipo(List<Tipousuarios> listatemp){
        tipousuarioslist.clear();
        agregarLista(tipousuarioslist,listatemp);
    }
    
    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        
        this.setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        int fila =0;
        if(Tabla.getSelectedRow()>=0)
        {
            fila = JOptionPane.showInternalConfirmDialog(this, "Desea Eliminar "
                + " el producto", "Confirmacion",1, 0);
            if(fila == JOptionPane.OK_OPTION)
            {
                //eliminar el producto
                if(CNUsuarios.eliminar(usuarios1))
                {
                    usuariosList.remove(usuarios1);
                    JOptionPane.showMessageDialog(this, "Se elimino Correctamente", 
                        "Informacion", JOptionPane.INFORMATION_MESSAGE);
                }
                else
                    JOptionPane.showMessageDialog(this, "No se ha podido Eliminar", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else
            JOptionPane.showMessageDialog(this, "Debe de Seleccionar un elemento", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
        
       
    }//GEN-LAST:event_btnEliminarActionPerformed

  
    
    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        //TODO add your handling code here:  
       if(Tabla.getSelectedRow()>= 0)
       {
           IngresoUsuario ing = new IngresoUsuario(obs, usuarios1);
           MDI.getDesktopPane().add(ing);           
           obs.addObserver(ing);
           Desactivar();
           ing.show();
       }
        
    }//GEN-LAST:event_btnModificarActionPerformed

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        // TODO add your handling code here:
        if(txtNombre.getText().length() >=2)
        {    
            CargarTablaUsuarios(CNUsuarios.buscarPorNombreDeUsuario(txtNombre.getText()));
        }
        if(txtNombre.getText().length() ==2)
            CargarTablaUsuarios(CNUsuarios.buscarActivos());
    }//GEN-LAST:event_txtNombreKeyTyped

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        // TODO add your handling code here:
        IngresoUsuario ing = new IngresoUsuario(obs);
        MDI.getDesktopPane().add(ing);        
        obs.addObserver(ing);
        Desactivar();
        ing.show();
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void TablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaMouseClicked
        // TODO add your handling code here:
        //int fila = Tabla.rowAtPoint(evt.getPoint());
        //proveedores1 =proveedorList.get(fila);
    }//GEN-LAST:event_TablaMouseClicked

    private void TablaTipoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaTipoMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_TablaTipoMouseClicked

    private void btnAgregar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregar1ActionPerformed
        // TODO add your handling code here:
        IngresoTipoUsuario ing = new IngresoTipoUsuario(obs);
        MDI.getDesktopPane().add(ing);        
        obs.addObserver(ing);
        Desactivar();
        ing.show();
        
    }//GEN-LAST:event_btnAgregar1ActionPerformed

    private void btnModificar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificar1ActionPerformed
        // TODO add your handling code here:
        if(TablaTipo.getSelectedRow()>= 0)
       {
           IngresoTipoUsuario ing = new IngresoTipoUsuario(obs, tipousuarios1);
           MDI.getDesktopPane().add(ing);           
           obs.addObserver(ing);
           Desactivar();
           ing.show();
       }
    }//GEN-LAST:event_btnModificar1ActionPerformed

    private void btnEliminar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminar1ActionPerformed
        // TODO add your handling code here:
        int fila =0;
        if(TablaTipo.getSelectedRow()>=0)
        {
            fila = JOptionPane.showInternalConfirmDialog(this, "Desea Eliminar "
                + " el producto", "Confirmacion",1, 0);
            if(fila == JOptionPane.OK_OPTION)
            {
                //eliminar el producto
                if(CNTipoUsuarios.eliminar(tipousuarios1))
                {
                    tipousuarioslist.remove(tipousuarios1);
                    JOptionPane.showMessageDialog(this, "Se elimino Correctamente", 
                        "Informacion", JOptionPane.INFORMATION_MESSAGE);
                }
                else
                    JOptionPane.showMessageDialog(this, "No se ha podido Eliminar", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else
            JOptionPane.showMessageDialog(this, "Debe de Seleccionar un elemento", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btnEliminar1ActionPerformed

    private void TablaPuestoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaPuestoMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_TablaPuestoMouseClicked

    private void btnAgregar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregar2ActionPerformed
        // TODO add your handling code here:
        IngresoPuesto ing = new IngresoPuesto(obs);
        MDI.getDesktopPane().add(ing);   
        Desactivar();
        ing.show();
    }//GEN-LAST:event_btnAgregar2ActionPerformed

    private void btnModificar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificar2ActionPerformed
        // TODO add your handling code here:
        if(TablaPuesto.getSelectedRow()>= 0)
       {
           IngresoPuesto ing = new IngresoPuesto(obs, puestos1);
           MDI.getDesktopPane().add(ing);   
           Desactivar();
           ing.show();
       }
    }//GEN-LAST:event_btnModificar2ActionPerformed

    private void btnEliminar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminar2ActionPerformed
        // TODO add your handling code here:
        
        int fila =0;
        if(TablaPuesto.getSelectedRow()>=0)
        {
            fila = JOptionPane.showInternalConfirmDialog(this, "Desea Eliminar "
                + " el producto", "Confirmacion",1, 0);
            if(fila == JOptionPane.OK_OPTION)
            {
                //eliminar el producto
                if(CNPuestos.eliminar(puestos1))
                {
                    puestoslist.remove(puestos1);
                    JOptionPane.showMessageDialog(this, "Se elimino Correctamente", 
                        "Informacion", JOptionPane.INFORMATION_MESSAGE);
                }
                else
                    JOptionPane.showMessageDialog(this, "No se ha podido Eliminar", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else
            JOptionPane.showMessageDialog(this, "Debe de Seleccionar un elemento", 
                    "Informacion", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_btnEliminar2ActionPerformed

    private void btnEliminar3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminar3ActionPerformed
        // TODO add your handling code here:
        IngresoMesa ing = new IngresoMesa();
        MDI.getDesktopPane().add(ing);   
        ing.show();
    }//GEN-LAST:event_btnEliminar3ActionPerformed

    private void btnAgregar3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregar3ActionPerformed
        // TODO add your handling code here:
        txtNombre.setText("");
        buscarTodos();
    }//GEN-LAST:event_btnAgregar3ActionPerformed

    private void buscarTodos()
    {
        CargarTablaUsuarios(CNUsuarios.buscarActivos());
    }
    
    public void agregarLista(List lista, List nuevaLista)
    {
        if(nuevaLista!= null)
        {
            Iterator<?> ite = nuevaLista.iterator();
            while(ite.hasNext())
                lista.add(ite.next());
        }
        
    }
    
    private void Desactivar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(false);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(false);
    }
    private void Activar()
    {
        for(Component x :this.jPanel2.getComponents())
            x.setEnabled(true);
        for(Component x : this.jLayeredPane3.getComponents())
            x.setEnabled(true);
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tabla;
    private javax.swing.JTable TablaPuesto;
    private javax.swing.JTable TablaTipo;
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnAgregar1;
    private javax.swing.JButton btnAgregar2;
    private javax.swing.JButton btnAgregar3;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnEliminar1;
    private javax.swing.JButton btnEliminar2;
    private javax.swing.JButton btnEliminar3;
    private javax.swing.JButton btnModificar;
    private javax.swing.JButton btnModificar1;
    private javax.swing.JButton btnModificar2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JLayeredPane jLayeredPane4;
    private javax.swing.JLayeredPane jLayeredPane5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private entidad.Puestos puestos1;
    private java.util.List<entidad.Puestos> puestoslist;
    private entidad.Tipousuarios tipousuarios1;
    private java.util.List<entidad.Tipousuarios> tipousuarioslist;
    private javax.swing.JTextField txtNombre;
    private entidad.Usuarios usuarios1;
    private java.util.List<entidad.Usuarios> usuariosList;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
       Activar();
       CargarTablaUsuarios(CNUsuarios.buscarActivos());
       CargarTablaTipo(CNTipoUsuarios.buscarActivos());
       CargarTablaPuestos(CNPuestos.buscarTodos());
       
    }
}
